package com.yfp.machine.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.machine.domain.MachineEventTrack;
import com.yfp.machine.service.MachineEventTrackService;
import com.yfp.machine.service.MachineLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * (MachineLog)表控制层
 *
 * 
 * @since 2023-12-16 22:48:58
 */
@Tag(name = "设备日志")
@RestController
@RequestMapping("machineLog")
public class MachineLogController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private MachineLogService machineLogService;

    @Resource
    private MachineEventTrackService machineEventTrackService;
    /**
     * 分页查询
     *
     * @param machineId 筛选条件
     * @return 查询结果
     */
    @GetMapping
    public TableDataInfo queryMachineLogByMachineId(@Parameter(name = "machineId") @Valid String machineId) {
        startPage();
        List<MachineEventTrack> machineLogs = this.machineEventTrackService.queryMachineEventTrackByMachineId(machineId);
        return getDataTable(machineLogs);
    }

    @GetMapping("/download")
    @Operation(summary = "下载设备日志")
    @Log(title = "下载设备日志", businessType = BusinessType.EXPORT)
    public R downloadMachineLog(@Parameter(name = "timeType") @Valid String timeType,
                                @Parameter(name = "machineId") @Valid String machineId,
                                @Parameter(name = "logType") @Valid String logType)
    {
        return this.machineLogService.downloadMachineLog(timeType, machineId, logType) ?
                R.ok(null, "请求日志成功,请稍后在列表中查看") : R.fail("请求日志失败");
    }
}

